package com.leyou.item.web;

import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exceptions.LyException;
import com.leyou.item.entity.Item;
import com.leyou.item.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private ItemService service;

    @PostMapping
    public ResponseEntity<Item> savaItem(Item item){
        if(item.getPrice()==null){
            throw new LyException(ExceptionEnum.INVALID_FILE_TYPE);  //点出来ExceptionEnum的对象

        }
        Item result = service.saveItem(item);

        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }
}
